package br.com.iqt.tests;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Postgres {
    public static void main(String args[]) {

        try {
      
            Class.forName("org.postgresql.Driver");
            Connection conn = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5432/tpch","postgres","123456");
            
            Statement st = conn.createStatement();
            ResultSet rs;
            int i;
            
            System.out.println("Executando consulta PostgreSQL ...");
            long tempoInicial = System.currentTimeMillis();
            rs = st.executeQuery("select * from region");
            long tempoFinal = System.currentTimeMillis();
            i=0;
            while(rs.next()) {
               i++;
            }
            System.out.println("Count = " + i + " - Tempo = " + (tempoFinal - tempoInicial));
            st.close();
            conn.close();
        }catch(Exception e) {
            System.out.println("Erro: " + e.getMessage());
        } finally {
            System.out.println("Conexao finalizada....");
        }
    }
}
